#!/bin/sh
#
# 数据库replication监控脚本
# 说明:2009-5-7 14:31:37 MySQL Replication在某些情况下，Errorno=0，但并不代表复制成功
#

#export PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin"

CURL=`which curl`
ALARM_URL='http://cacti.web.moxiu.com/moniter/moniter.php?h=121&e=dbrep'
DB_USER="mxrepc"
DB_PASS="0d06172c"
LAST_ERRORNO=`echo "show slave status\G"|mysql -u${DB_USER} -p${DB_PASS}| awk '$1=="Last_Errno:" {print $2}'`
LAST_ERROR=`echo "show slave status\G"|mysql -u${DB_USER} -p${DB_PASS}| awk '$1=="Last_Error:" {print $2}'`
ERR_LENGTH=`expr length "$LAST_ERROR"`

if [ "$ERR_LENGTH" -ne 0 ] 
then
	LAST_ERROR=`echo "show slave status\G"|mysql -uroot| awk '$1=="Last_Error:" {print $2}'`
	$CURL $ALARM_URL"&msg="$LAST_ERROR 
	#echo $LAST_ERROR >> /tmp/db_rep_err.sql
fi
